<html>
<head><meta charset="utf-8"><title>Doc comment AST? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html">Doc comment AST?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203384138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203384138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203384138">(Jul 09 2020 at 13:21)</a>:</h4>
<p>I am trying to improve doc comment parsing in rustc but I don't quite understand how the<br>
parser would pass the input of doc comment to helpers?</p>
<p>What would be the AST for this block doc comment?</p>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="sd">/**</span>
<span class="sd">     * this is insane</span>
<span class="sd">     *************/</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="203385063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203385063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203385063">(Jul 09 2020 at 13:30)</a>:</h4>
<p>Ping <span class="user-mention" data-user-id="116122">@simulacrum</span></p>



<a name="203385086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203385086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203385086">(Jul 09 2020 at 13:31)</a>:</h4>
<p>I don't know :)</p>



<a name="203385348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203385348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203385348">(Jul 09 2020 at 13:33)</a>:</h4>
<p>Sorry. Ping other rustdoc folks <span class="user-mention" data-user-id="210316">@GuillaumeGomez</span> <span class="user-mention" data-user-id="232545">@Joshua Nelson</span></p>



<a name="203385600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203385600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203385600">(Jul 09 2020 at 13:35)</a>:</h4>
<p>I wonder if rustdoc has some <code>-Z unpretty</code> option that would show it</p>



<a name="203385678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203385678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203385678">(Jul 09 2020 at 13:36)</a>:</h4>
<p>I don't know off the top of my head</p>



<a name="203385794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203385794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203385794">(Jul 09 2020 at 13:37)</a>:</h4>
<p><code>cargo expand</code> make block comment to line comment?</p>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">////**</span>
<span class="w">    </span><span class="sd">///     * this is insane</span>
<span class="w">    </span><span class="sd">///     *************/</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="203385917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203385917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203385917">(Jul 09 2020 at 13:38)</a>:</h4>
<p>Seems odd, wouldn't that include the <code>*</code>?</p>



<a name="203385926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203385926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203385926">(Jul 09 2020 at 13:38)</a>:</h4>
<p>Do those show up if you run cargo doc?</p>



<a name="203386084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203386084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203386084">(Jul 09 2020 at 13:40)</a>:</h4>
<p>You mean the old one or the one after expanded by cargo-expand?</p>



<a name="203386439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203386439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203386439">(Jul 09 2020 at 13:44)</a>:</h4>
<p>Either</p>



<a name="203386916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203386916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203386916">(Jul 09 2020 at 13:48)</a>:</h4>
<p>The old one: <a href="/user_uploads/4715/OSvmsgZMVZ4cItXN53HJHiaS/image.png">image.png</a> <br>
The expanded one: <a href="/user_uploads/4715/e3WsI3nBBvioKAjmv4eG4zXV/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/OSvmsgZMVZ4cItXN53HJHiaS/image.png" title="image.png"><img src="/user_uploads/4715/OSvmsgZMVZ4cItXN53HJHiaS/image.png"></a></div><div class="message_inline_image"><a href="/user_uploads/4715/e3WsI3nBBvioKAjmv4eG4zXV/image.png" title="image.png"><img src="/user_uploads/4715/e3WsI3nBBvioKAjmv4eG4zXV/image.png"></a></div>



<a name="203391289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203391289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203391289">(Jul 09 2020 at 14:21)</a>:</h4>
<p>Cargo expand is lying to you then, that's fun</p>



<a name="203392579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203392579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203392579">(Jul 09 2020 at 14:31)</a>:</h4>
<p>That's the same output if you pass <code>-Z unpretty=hir</code> to rustc.</p>



<a name="203392720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203392720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203392720">(Jul 09 2020 at 14:32)</a>:</h4>
<p>maybe I'm misunderstanding the question, but you can use <code>-Zast-json</code> or <code>-Zast-json-noexpand</code> to see the AST.  Or are you asking about how rustdoc parses the comment itself?</p>



<a name="203392881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203392881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203392881">(Jul 09 2020 at 14:34)</a>:</h4>
<p>I'm mostly asking about this file: <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_ast/util/comments.rs">https://github.com/rust-lang/rust/blob/master/src/librustc_ast/util/comments.rs</a></p>



<a name="203393001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203393001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203393001">(Jul 09 2020 at 14:34)</a>:</h4>
<p>which is belong to ast I think</p>



<a name="203393104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203393104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203393104">(Jul 09 2020 at 14:35)</a>:</h4>
<p>The function like <a href="https://github.com/rust-lang/rust/blob/5db778affee7c6600c8e7a177c48282dab3f6292/src/librustc_ast/util/comments.rs#L48">https://github.com/rust-lang/rust/blob/5db778affee7c6600c8e7a177c48282dab3f6292/src/librustc_ast/util/comments.rs#L48</a><br>
I am not clear about its input form</p>



<a name="203393706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203393706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203393706">(Jul 09 2020 at 14:39)</a>:</h4>
<p>In your example, I think it would be <code>"/**\n     * this is insane\n     *************/"</code> from the <code>#[doc]</code> attribute.</p>



<a name="203393960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Doc%20comment%20AST%3F/near/203393960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Doc.20comment.20AST.3F.html#203393960">(Jul 09 2020 at 14:41)</a>:</h4>
<p>thank you. I will investigate more.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>